<?php 
//-------------------------------------------------------------
//copyright: by you

//-------------------------------------------------------------

$ftp_server = "symbianmate.com"; 
$conn_id = ftp_connect ($ftp_server) 
    or die("Couldn't connect to $ftp_server"); 
    
$login_result = ftp_login($conn_id, "username", "pass"); 
if ((!$conn_id) || (!$login_result)) 
    die("FTP Connection Failed"); 
ftp_pasv($conn_id,true);  //needed since you may be behind a firewall

// changing the initial path on remote ftp server to public_html
ftp_chdir($conn_id,"public_html"); 

// getting the name of folder to copy recursively
// u may use a "." if u want to copy the whole structure inside public_html as it is.
$src=$_GET['src'];

ftp_sync ($src);  

ftp_close($conn_id);  

// ftp_sync - Copy directory and file structure 
function ftp_sync ($dir) { 

    global $conn_id; 

    if ($dir != ".") { 
        if (ftp_chdir($conn_id, $dir) == false) { 
            echo ("Change Dir Failed: $dir<BR>\r\n"); 
            return; 
        } 
        if (!(is_dir($dir))) 
            mkdir($dir); 
        chdir ($dir); 
    } 

    $contents = ftp_nlist($conn_id, "."); 
    foreach ($contents as $file) { 
    
        if ($file == '.' || $file == '..') 
            continue; 
        
        if (@ftp_chdir($conn_id, $file)) { 
            ftp_chdir ($conn_id, ".."); 
            ftp_sync ($file); 
        } 
        else 
            ftp_get($conn_id, $file, $file, FTP_BINARY); 
    } 
        
    ftp_chdir ($conn_id, ".."); 
    chdir (".."); 

} 
?>
